package solutions.leetcode.easy;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/">26. 删除有序数组中的重复项</a>
 */
public class Solution26 {

    public int removeDuplicates(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int p = 1, e = 1, v = nums[0];
        while (p < nums.length) {
            if (nums[p] == v) {
                p++;
            } else {
                nums[e] = nums[p];
                v = nums[p];
                p++;
                e++;
            }
        }
        return e;
    }

    public static void main(String[] args) {
        Solution26 solution = new Solution26();
        System.out.println(solution.removeDuplicates(new int[] {0,0,1,1,1,2,2,3,3,4}));
    }
}
